module FRM_FAS_COMPARE(
   RESET,
   RCLK_155M,

   MATCH_VECTOR,
   MATCH_HIT,
   MATCH_POINT
   );

input              RESET;
input              RCLK_155M;
input[135:1]       MATCH_VECTOR;
output reg         MATCH_HIT;
output reg[2:0]    MATCH_POINT;

reg[7:0]           MATCH_FLAG;

//*** compare MTCH_VECTOR with FAS, generate match flag  ***//
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_COMPARE7
   if ( RESET==1'b1 )
      MATCH_FLAG[7]                 <=1'b0;
   else begin
      if ( MATCH_VECTOR[135:8]==128'hF6F6F6F6_F6F6F6F6_28282828_28282828)
         MATCH_FLAG[7]              <=1'b1;
      else
         MATCH_FLAG[7]              <=1'b0;
   end
end
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_COMPARE6
   if ( RESET==1'b1 )
      MATCH_FLAG[6]                 <=1'b0;
   else begin
      if ( MATCH_VECTOR[134:7]==128'hF6F6F6F6_F6F6F6F6_28282828_28282828)
         MATCH_FLAG[6]              <=1'b1;
      else
         MATCH_FLAG[6]              <=1'b0;
   end
end
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_COMPARE5
   if ( RESET==1'b1 )
      MATCH_FLAG[5]                 <=1'b0;
   else begin
      if ( MATCH_VECTOR[133:6]==128'hF6F6F6F6_F6F6F6F6_28282828_28282828)
         MATCH_FLAG[5]              <=1'b1;
      else
         MATCH_FLAG[5]              <=1'b0;
   end
end
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_COMPARE4
   if ( RESET==1'b1 )
      MATCH_FLAG[4]                 <=1'b0;
   else begin
      if ( MATCH_VECTOR[132:5]==128'hF6F6F6F6_F6F6F6F6_28282828_28282828)
         MATCH_FLAG[4]              <=1'b1;
      else
         MATCH_FLAG[4]              <=1'b0;
   end
end
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_COMPARE3
   if ( RESET==1'b1 )
      MATCH_FLAG[3]                 <=1'b0;
   else begin
      if ( MATCH_VECTOR[131:4]==128'hF6F6F6F6_F6F6F6F6_28282828_28282828)
         MATCH_FLAG[3]              <=1'b1;
      else
         MATCH_FLAG[3]              <=1'b0;
   end
end
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_COMPARE2
   if ( RESET==1'b1 )
      MATCH_FLAG[2]                 <=1'b0;
   else begin
      if ( MATCH_VECTOR[130:3]==128'hF6F6F6F6_F6F6F6F6_28282828_28282828)
         MATCH_FLAG[2]              <=1'b1;
      else
         MATCH_FLAG[2]              <=1'b0;
   end
end
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_COMPARE1
   if ( RESET==1'b1 )
      MATCH_FLAG[1]                 <=1'b0;
   else begin
      if ( MATCH_VECTOR[129:2]==128'hF6F6F6F6_F6F6F6F6_28282828_28282828)
         MATCH_FLAG[1]              <=1'b1;
      else
         MATCH_FLAG[1]              <=1'b0;
   end
end
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_COMPARE0
   if ( RESET==1'b1 )
      MATCH_FLAG[0]                 <=1'b0;
   else begin
      if ( MATCH_VECTOR[128:1]==128'hF6F6F6F6_F6F6F6F6_28282828_28282828)
         MATCH_FLAG[0]              <=1'b1;
      else
         MATCH_FLAG[0]              <=1'b0;
   end
end

// encode match position to 0-7
always @(posedge RESET or posedge RCLK_155M) begin : MACTH_ENCODE
   if ( RESET==1'b1 ) begin
      MATCH_HIT                     <= 1'b0;
      MATCH_POINT[2:0]              <= 3'd0;
   end
   else begin
      case ( MATCH_FLAG[7:0] )
      8'b1000_0000:   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b1_111;
      8'b0100_0000:   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b1_110;
      8'b0010_0000:   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b1_101;
      8'b0001_0000:   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b1_100;
      8'b0000_1000:   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b1_011;
      8'b0000_0100:   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b1_010;
      8'b0000_0010:   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b1_001;
      8'b0000_0001:   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b1_000;
      default     :   {MATCH_HIT, MATCH_POINT[2:0]}        <= 4'b0_000;
      endcase
   end
end
endmodule
